package com.atguigu.daijia.driver.service.impl;

import com.atguigu.daijia.common.execption.GuiguException;
import com.atguigu.daijia.common.result.Result;
import com.atguigu.daijia.common.result.ResultCodeEnum;
import com.atguigu.daijia.driver.client.CosFeignClient;
import com.atguigu.daijia.driver.service.CosService;
import com.atguigu.daijia.model.vo.driver.CosUploadVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Slf4j
@Service
@SuppressWarnings({"unchecked", "rawtypes"})
public class CosServiceImpl implements CosService {


    @Resource
    private CosFeignClient cosFeignClient;


    /**
     * 文件上传
     * @param file
     * @param path
     * @return
     */
    @Override
    public CosUploadVO uploadFile(MultipartFile file, String path) {
        Result<CosUploadVO> r = cosFeignClient.upload(file, path);
        if (r.getCode().equals(ResultCodeEnum.FAIL.getCode())) {
            throw new GuiguException(ResultCodeEnum.FEIGN_FAIL);
        }
        return r.getData();
    }
}
